//
//  YRightViewController.m
//  YSiReader
//
//  Created by yanxuewen on 2016/12/8.
//  Copyright © 2016年 yxw. All rights reserved.
//

#import "YRightViewController.h"
#import "YSearchViewController.h"
#import "YRankingViewController.h"

@interface YRightViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (strong, nonatomic) NSArray *dataArr;
@property (strong, nonatomic) NSArray *testArr;
@property (strong, nonatomic) NSArray *imageArr;

@end

@implementation YRightViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _testArr = @[@"搜索",@"排行榜"];
    _imageArr = @[@"rsm_icon_0",@"rsm_icon_3"];
    
    [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"YReuseCell"];
    _tableView.rowHeight = 50;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0.01;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.01;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _testArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"YReuseCell" forIndexPath:indexPath];
    cell.backgroundColor = YRGBColor(40, 40, 40);
    cell.textLabel.textColor = YRGBColor(230, 230, 230);
    UIView *bgview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.width, tableView.rowHeight)];
    bgview.backgroundColor = YRGBColor(28, 28, 28);
    cell.selectedBackgroundView = bgview;
    cell.imageView.image = [UIImage imageNamed:_imageArr[indexPath.row]];
    cell.textLabel.text = _testArr[indexPath.row];
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, tableView.rowHeight - 1.5, tableView.width, 1.5)];
    line.backgroundColor = YRGBColor(20, 20, 20);
    [cell addSubview:line];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.row == 0) {
        YSearchViewController *searchVC = [[YSearchViewController alloc] init];
        [self.navigationController pushViewController:searchVC animated:YES];
    } else if(indexPath.row == 1) {
        YRankingViewController *rankingVC = [[YRankingViewController alloc] init];
        [self.navigationController pushViewController:rankingVC animated:YES];
    }
}

@end
